/*    */ package com.zimbra.cs.datasource;
/*    */ 
/*    */ import com.zimbra.common.account.Key.DataSourceBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.StringUtil;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.DataSource;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.MailboxManager;
/*    */ import com.zimbra.cs.mailbox.ScheduledTask;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class DataSourceTask
/*    */   extends ScheduledTask
/*    */ {
/*    */   private static final String KEY_DATA_SOURCE_ID = "dsid";
/*    */   
/*    */   public DataSourceTask() {}
/*    */   
/*    */   public DataSourceTask(int mailboxId, String accountId, String dataSourceId, long intervalMillis)
/*    */   {
/* 42 */     if (StringUtil.isNullOrEmpty(accountId)) {
/* 43 */       throw new IllegalArgumentException("accountId cannot be null or empty");
/*    */     }
/* 45 */     if (StringUtil.isNullOrEmpty(dataSourceId)) {
/* 46 */       throw new IllegalArgumentException("dataSourceId cannot be null or empty");
/*    */     }
/*    */     
/* 49 */     setMailboxId(mailboxId);
/* 50 */     setProperty("dsid", dataSourceId);
/* 51 */     setIntervalMillis(intervalMillis);
/*    */   }
/*    */   
/* 54 */   public String getName() { return getDataSourceId(); }
/*    */   
/*    */   public String getDataSourceId() {
/* 57 */     return getProperty("dsid");
/*    */   }
/*    */   
/*    */   public Void call() {
/* 61 */     ZimbraLog.clearContext();
/* 62 */     ZimbraLog.addMboxToContext(getMailboxId());
/* 63 */     ZimbraLog.datasource.debug("Running scheduled import for DataSource %s", new Object[] { getDataSourceId() });
/*    */     
/* 65 */     Mailbox mbox = null;
/*    */     
/*    */     try
/*    */     {
/* 69 */       mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/* 70 */       Account account = mbox.getAccount();
/* 71 */       ZimbraLog.addAccountNameToContext(account.getName());
/* 72 */       Provisioning prov = Provisioning.getInstance();
/* 73 */       DataSource ds = prov.get(account, Key.DataSourceBy.id, getDataSourceId());
/* 74 */       if (ds != null) {
/* 75 */         ZimbraLog.addDataSourceNameToContext(ds.getName());
/* 76 */         if (!ds.isEnabled()) {
/* 77 */           ZimbraLog.datasource.info("DataSource is disabled.  Cancelling future tasks.");
/* 78 */           DataSourceManager.cancelTask(mbox, getDataSourceId());
/* 79 */           return null;
/*    */         }
/*    */         
/*    */ 
/* 83 */         DataSourceManager.importData(ds);
/*    */       } else {
/* 85 */         ZimbraLog.datasource.info("DataSource %s was deleted.  Cancelling future tasks.", new Object[] { getDataSourceId() });
/*    */         
/* 87 */         DataSourceManager.cancelTask(mbox, getDataSourceId());
/*    */       }
/*    */     } catch (ServiceException e) {
/* 90 */       ZimbraLog.datasource.warn("Scheduled DataSource import failed.", e);
/* 91 */       return null;
/*    */     }
/*    */     
/* 94 */     ZimbraLog.clearContext();
/* 95 */     return null;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/DataSourceTask.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */